﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace EfCore.Data.Migrations
{
    public partial class provinceAddMap : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_City_Province_ProvinceId",
                table: "City");

            migrationBuilder.DropPrimaryKey(
                name: "PK_Province",
                table: "Province");

            migrationBuilder.RenameTable(
                name: "Province",
                newName: "T_Province");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "T_Province",
                maxLength: 30,
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_T_Province",
                table: "T_Province",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_T_Province_Name",
                table: "T_Province",
                column: "Name");

            migrationBuilder.AddForeignKey(
                name: "FK_City_T_Province_ProvinceId",
                table: "City",
                column: "ProvinceId",
                principalTable: "T_Province",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_City_T_Province_ProvinceId",
                table: "City");

            migrationBuilder.DropPrimaryKey(
                name: "PK_T_Province",
                table: "T_Province");

            migrationBuilder.DropIndex(
                name: "IX_T_Province_Name",
                table: "T_Province");

            migrationBuilder.RenameTable(
                name: "T_Province",
                newName: "Province");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Province",
                nullable: true,
                oldClrType: typeof(string),
                oldMaxLength: 30);

            migrationBuilder.AddPrimaryKey(
                name: "PK_Province",
                table: "Province",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_City_Province_ProvinceId",
                table: "City",
                column: "ProvinceId",
                principalTable: "Province",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
